package com.macaline.concurrent;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;


class MyTash implements Callable{

    @Override
    public Integer call() throws Exception {
        System.out.println(Thread.currentThread().getName() + " 2 finish！");

        return 2;
    }
}

public class CallAbleDemo {


    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask futureTask = new FutureTask<Integer>(()->{
            TimeUnit.SECONDS.sleep(1);
            System.out.println(Thread.currentThread().getName() + " 1024 finish！");
            return 1024;
        });
        new Thread(futureTask, "AA").start();

        while (!futureTask.isDone()) {
            System.out.println("wait...");
        }

        System.out.println(futureTask.get());
        System.out.println(futureTask.get());
        System.out.println(futureTask.get());

        FutureTask<Integer> integerFutureTask = new FutureTask<Integer>(new MyTash());
        new Thread(integerFutureTask, "BB").start();

        System.out.println(integerFutureTask.get());

    }

}
